import { http } from "@/utils/http";
import type { ResultProps } from "@/api/user";

export interface DeviceEnterProp {
  id: number;
  device_id: string;
  device_model: string;
  device_type: DeviceType;
  is_activation: number;
  create_time: Date;
  device?: Device | null;
  business_val?: number | string;
}

export interface Device {
  id: number;
  account_id: number;
  business_id: number;
  store_id: number | null;
  device_id: string;
  name: DeviceType | null;
  android_id: null | string;
  device_model: string;
  device_type: DeviceType;
  system_version: null | string;
  brand: null | string;
  province: null | string;
  city: null | string;
  device_status: number;
  run_status: number;
  delete_status: number;
  activation_time: Date;
  lock_time: Date | null;
  update_time: Date;
  create_time: Date;
  store_name: null | string;
  business_name: string;
  operator: null;
  phone: null;
  net_status: null;
}

export const getDeviceEnterList = (params?: object) => {
  return http.request<ResultProps<DeviceEnterProp[]>>(
    "get",
    "/deviceEnter/getList",
    {
      params: {
        ...params,
        hiddenDeviceType: true
      }
    }
  );
};

export interface DeviceListProp {
  id: number;
  account_id: number;
  business_id: number;
  store_id: number | null;
  device_id: string;
  name: null | string;
  android_id: null;
  device_model: string;
  device_type: DeviceType;
  system_version: null;
  brand: null | string;
  province: null | string;
  city: null | string;
  device_status: number;
  run_status: number;
  delete_status: number;
  activation_time: Date;
  lock_time: Date | null;
  update_time: Date;
  create_time: Date;
  store_name: null | string;
  deviceFormulaUseRecord: DeviceFormulaUseRecord | null;
  releaseRecord: ReleaseRecord | null;
  business_name: null;
  operator: null | string;
  phone: null | string;
  calibration_time: Date | null;
  net_status: number | null;
}

export interface DeviceFormulaUseRecord {
  id: number;
  deviceId: string;
  version: number;
  name: string;
  useTime: Date;
}

export enum DeviceType {
  柜式机 = "柜式机",
  泡茶机 = "泡茶机",
  混料机 = "混料机"
}

export interface ReleaseRecord {
  releaseTime: Date;
  name: string;
  version: number;
}

export const getDeviceList = (data?: object) => {
  return http.request<ResultProps<DeviceListProp[]>>(
    "post",
    "/device/getList",
    {
      data: {
        ...data,
        hiddenDeviceType: true
      }
    }
  );
};

export const addDeviceEnterList = (data?: object) => {
  return http.request<ResultProps<DeviceEnterProp[]>>(
    "post",
    "/deviceEnter/add",
    {
      data
    }
  );
};

export interface SoftwareUpgradeListProps {
  id: number;
  account_id: number;
  business_id: number;
  business_name: string;
  device_type: string;
  device_model: string;
  link: string;
  size: string;
  version: string;
  content: string;
  is_force: boolean;
  upgrade_type: number;
  use_test: number;
  boards: string;
  version_name: string;
  create_time: Date;
  update_time: Date;
}

export const softwareUpgradeGetList = (params?: object) => {
  return http.request<ResultProps<SoftwareUpgradeListProps[]>>(
    "get",
    "/softwareUpgrade/getList",
    {
      params
    }
  );
};

export const softwareUpgradeAdd = (data?: object) => {
  return http.request<ResultProps<any>>("post", "/softwareUpgrade/add", {
    data
  });
};

export const softwareUpgradeUpdate = (data?: object) => {
  return http.request<ResultProps<any>>("post", "/softwareUpgrade/upd", {
    data
  });
};

export const softwareUpgradeDel = (data?: object) => {
  return http.request<ResultProps<any>>("post", "/softwareUpgrade/del", {
    data
  });
};

export interface RecordModel {
  /**
   * 过滤条件
   */
  filter: Filter;
  /**
   * 一页几个
   */
  size?: number;
  /**
   * 开始页
   */
  start_page?: number;

  [property: string]: any;
}

/**
 * 过滤条件
 */
export interface Filter {
  /**
   * 软件升级版本的自增ID，ID 编号
   */
  upgrade_id: number;

  [property: string]: any;
}

export const softwareUpgradeGetRecordList = (data?: RecordModel) => {
  return http.requestJson<ResultProps<SoftwareUpgradeListProps[]>>(
    "post",
    "/softwareUpgrade/getRecordList",
    {
      data
    }
  );
};

export interface deviceEnterListModelProp {
  device_model: string;
}

export const deviceEnterGetListModel = (params?: object) => {
  return http.request<ResultProps<deviceEnterListModelProp[]>>(
    "get",
    "/deviceEnter/getListModel",
    {
      params
    }
  );
};

export const deviceEnterAdd = (data?: object) => {
  return http.request<ResultProps<any>>("post", "/deviceEnter/add", {
    data
  });
};

export const deviceEnterUpd = (data?: object) => {
  return http.request<ResultProps<any>>("post", "/deviceEnter/upd", {
    data
  });
};

export const deviceEnterDel = (data?: object) => {
  return http.request<ResultProps<any>>("post", "/deviceEnter/del", {
    data
  });
};

export const deviceActivation = (data?: object) => {
  return http.request<ResultProps<any>>("post", "/device/activation", {
    data
  });
};

export const deviceRedistribution = (data?: object) => {
  return http.request<ResultProps<any>>("post", "/device/redistribution", {
    data
  });
};
